/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-10 下午09:58:58
 *
 * PersonalDetailAction.java 
 *
 *******************************************************************/
package com.transer.web.action.search;

import java.util.List;

import com.transer.persistance.bean.Project;
import com.transer.persistance.bean.User;
import com.transer.persistance.dao.IProjectDao;
import com.transer.persistance.dao.IUserDao;
import com.transer.web.action.TranserActionSupport;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class UserDetailAction extends TranserActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3019489992792170758L;
	/** 用户操作 */
	private IUserDao userDao;
	/** 项目操作 */
	private IProjectDao projectDao;
	/** 用户 */
	private User user;
	/** 用户ID */
	private int uid;
	/** 用户发布的项目 */
	private List<Project> published;
	/** 发布项目数量 */
	private int publishedSize;
	/** 方法 */
	private String method;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// 如果是查看翻译方
		if ("transer".equals(method)) {
			return executeTranser();
		} else if ("publisher".equals(method)) {// 发布方
			return executePublisher();
		} else {
			return TranserActionSupport.SUCCESS;
		}
	}

	// 查看接包方详细信息
	private String executeTranser() throws Exception {
		// 获取用户
		user = userDao.getUserByID(uid);
		return TranserActionSupport.SUCCESS;
	}

	// 查看发布方详细信息
	private String executePublisher() throws Exception {
		// 获取用户
		user = userDao.getUserByID(uid);
		// 不存在用户
		if (user == null) {
			return TranserActionSupport.SUCCESS;
		}
		// 获取最近发布项目
		published = projectDao.getPublishedProjects(user.getId(), 0, 5);
		// 获取发布项目数量
		publishedSize = projectDao.getPublishedSize(user.getId());
		// 返回
		return "publisher";
	}

	/**
	 * @return the userDao
	 */
	public IUserDao getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @return the uid
	 */
	public int getUid() {
		return uid;
	}

	/**
	 * @param uid
	 *            the uid to set
	 */
	public void setUid(int uid) {
		this.uid = uid;
	}

	/**
	 * @return the published
	 */
	public List<Project> getPublished() {
		return published;
	}

	/**
	 * @param published
	 *            the published to set
	 */
	public void setPublished(List<Project> published) {
		this.published = published;
	}

	/**
	 * @return the projectDao
	 */
	public IProjectDao getProjectDao() {
		return projectDao;
	}

	/**
	 * @param projectDao
	 *            the projectDao to set
	 */
	public void setProjectDao(IProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	/**
	 * @return the publishedSize
	 */
	public int getPublishedSize() {
		return publishedSize;
	}

	/**
	 * @param publishedSize
	 *            the publishedSize to set
	 */
	public void setPublishedSize(int publishedSize) {
		this.publishedSize = publishedSize;
	}

	/**
	 * @return the method
	 */
	public String getMethod() {
		return method;
	}

	/**
	 * @param method
	 *            the method to set
	 */
	public void setMethod(String method) {
		this.method = method;
	}
}
